layui.config({
    base: 'assets/layuiadmin/' //静态资源所在路径
}).extend({
    index: 'lib/index' //主入口模块
}).use(['index', 'form', 'laydate'], function(){
    var $ = layui.$,
        laydate = layui.laydate,
        form = layui.form;

    laydate.render({
        elem: '#time', //指定元素
        type: 'datetime',
        range: true
    });

    var typeDatas;
    var userId = $('#userId').val();
    post('user/toEditImLimit', {'userId': userId}, false,function (data) {
        typeDatas = data;

        var type = $("input[type='radio']:checked").val();
        renderer(data, type);
    });

    //监控redio单选
    form.on('radio(type)', function(data){
        var type = data.value;
        renderer(type);
    });

    //渲染数据
    function renderer(data, type){
        if(data == undefined){
            return;
        }
        var typeData = data[type];
        if(typeData == undefined){
            $('#num').val('')
            $('#time').val('');
        }else{
            $('#num').val(typeData.num)
            $('#time').val(typeData.beginTime +" - "+typeData.endTime);
        }
    }

    form.on('radio(type)', function(data){
        var type = data.value;
        renderer(typeDatas, type);
    });

});